package com.wasu.controller;

import java.util.List;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.wasu.jopo.User;
import com.wasu.jopo.UserQuery;
import com.wasu.mapper.UserMapper;
import com.wasu.service.UserService;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "findUserById/{id}", method = RequestMethod.GET)
	public User findUserById(@PathVariable("id") Integer id) {
		log.info("根据 id: " + id + " 查询用户信息");
		User user = userService.selectByPrimaryKey(id);
		return user;
	}
	
	@RequestMapping("add")
	public void add(User user) {
		userService.insert(user);
	}
	
	@RequestMapping("findAll")
	public List<User> findAll(){
		UserQuery userQuery = new UserQuery();
		return userService.selectByExample(userQuery);
	}
	
	@RequestMapping(value = "findRedis/{id}", method = RequestMethod.GET)
	public String findRedis(@PathVariable("id") Integer id ) {
		String findRedis = userService.findRedis(id);
		return findRedis;
	}
	
	@RequestMapping("addRedis")
	public void addRedis(User user) {
		userService.addRedis(user);
	}

}
